package socket;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author MaoLin Wang
 * @description
 * @date 2020/9/30 9:03 上午
 */
public class Client {
    public static void main(String[] args) {

        for (int i = 0; i < 20; i++) {
            RpcRequest rpcRequest=new RpcRequest("hello","sayHello",i);

            Socket socket=new Socket();
            try {
                socket.connect(new InetSocketAddress("127.0.0.1",9001));
                try(ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
                    ObjectInputStream ois=new ObjectInputStream(socket.getInputStream())){
                    oos.writeObject(rpcRequest);
                    oos.flush();
                    String resp = (String) ois.readObject();
                    System.out.println("receive response from server ,message is :"+resp);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
